package com.netx.ebs;
import com.netx.data.EntityInstance;
import com.netx.generics.sql.Row;
import com.netx.generics.time.Date;


public class User extends EntityInstance {

	private final String _username;
	private final String _password;
	private final String _name;
	private final char _sex;
	private final Date _birthdate;
	private final Date _registrationDate;
	private final int _sessionTimeoutTime;
	private Role _role;
	private Permission[] _permissions;
	
	User(Row data, Role r, Permission[] perms) {
		super(data.getLong(1));
		_username = data.getString(2);
		_password = data.getString(3);
		_name = data.getString(4);
		_sex = data.getChar(5);
		_birthdate = data.getDate(6);
		_registrationDate = data.getDate(7);
		_sessionTimeoutTime = data.getInt(8);
		_role = r;
		_permissions = perms;
	}

	public String toString() {
		return "User: \""+_username+"\"";
	}
	
	public String getUsername() {
		return _username;
	}

	public String getPassword() {
		return _password;
	}

	public String getName() {
		return _name;
	}

	public char getSex() {
		return _sex;
	}
	public Date getBirthDate() {
		return _birthdate;
	}

	public Date getRegistrationDate() {
		return _registrationDate;
	}
	
	public int getSessionTimeoutTime() {
		return _sessionTimeoutTime;
	}

	public Role getRole() {
		return _role;
	}
	
	public Permission[] getPermissions() {
		return _permissions;
	}
	
	// for Users and Roles:
	void setRole(Role r) {
		_role = r;
	}

	// for Users:
	void setPermissions(Permission[] perms) {
		_permissions = perms;
	}
}
